package main.reports;

import main.Link.LinkArray;
import main.Trees.ProjectNode;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;

public class SumTableDataDialog extends javax.swing.JDialog {

    private Connection connSQL;
    private Frame parent;
    private LinkArray linkArray;
    private ArrayList<ProjectNode> projectList;
    String sectionSelect;

    public SumTableDataDialog (Frame parent, boolean modal, ArrayList<ProjectNode> projectList, Connection connSQL, String sectionSelect) {
        super(parent, modal);
        initComponents();

        this.projectList = projectList;
        this.connSQL = connSQL;
        this.parent = parent;
        this.sectionSelect = sectionSelect;

//        jLabel11.setText("Текущий проект: \""+curProject.getShortName()+ " - "+ curProject.getName().substring(1, curProject.getName().length() > 30 ? 30 : curProject.getName().length())+"...\"");
        pack();

        InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
        ActionMap actionMap = getRootPane().getActionMap();
        actionMap.put("cancel", new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });
    }

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
        dispose();
    }

    private void buttonOpen3ActionPerformed(java.awt.event.ActionEvent evt) {
//        XLSSetup report = new XLSSetup();
//        setVisible(false);
//        String path = report.generate(projectList, connSQL, sectionSelect);



//        if (path != null) {
//
//            Object[] options = {"Ок"};
//
//            int choice = JOptionPane.showOptionDialog(parent,
//                    "Выгрузка отчета по проекту: \"" + projectList.get(0).getName().replace("[ROOT]", "")+ "\"\nбыла успешно завершена.",
//                    "Завершено",
//                    JOptionPane.INFORMATION_MESSAGE,
//                    JOptionPane.INFORMATION_MESSAGE,
//                    null,
//                    options,
//                    options[0]);
//        }
        dispose();
    }

    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jSeparator10 = new javax.swing.JSeparator();
        buttonOpen3 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();

        setTitle("Экспорт отчета");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                dispose();
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jRadioButton3.setText("Выгрузить все данные без исключений для кодов вида PV3X");

        buttonGroup1.add(jRadioButton4);
        jRadioButton4.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jRadioButton4.setSelected(true);
        jRadioButton4.setText("Выгрузка трех отчетов с учетом правила разнесения данных (по умолчанию)");
        jRadioButton4.setToolTipText("");
        jRadioButton4.setVerifyInputWhenFocusTarget(false);

        jLabel10.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jLabel10.setText("Выберите метод выгрузки данных:");

        jLabel11.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jLabel11.setText("Текущй проект: БОСС");

        jButton6.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jButton6.setText("Отмена");
        jButton6.setMargin(new java.awt.Insets(6, 14, 6, 14));
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jSeparator10.setBackground(java.awt.SystemColor.control);
        jSeparator10.setForeground(java.awt.SystemColor.activeCaptionBorder);

        buttonOpen3.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        buttonOpen3.setText("Экспорт");
        buttonOpen3.setMargin(new java.awt.Insets(6, 14, 6, 14));
        buttonOpen3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOpen3ActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Segoe UI Light", 0, 18)); // NOI18N
        jLabel12.setText("Экспорт исходных данных для сводных таблиц в Excel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jSeparator10)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(buttonOpen3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6)
                                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(56, 56, 56))
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(55, 55, 55)
                                                .addComponent(jLabel12))
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(56, 56, 56)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel10)
                                                        .addComponent(jLabel11)
                                                        .addComponent(jRadioButton3)
                                                        .addComponent(jRadioButton4))))
                                .addContainerGap(56, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(jLabel12)
                                .addGap(6, 6, 6)
                                .addComponent(jSeparator10, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jRadioButton4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jRadioButton3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(buttonOpen3, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(55, 55, 55))
        );

        pack();
        setResizable(false);
    }

    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton buttonOpen3;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JSeparator jSeparator10;

}
